/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EdytujPietro.java
 *
 * Created on 2011-04-23, 19:32:45
 */

package View;

import Controller.ElementyBudynku.Budynek;
import Model.DAO.MsPietroDAO;

/**
 *
 * @author matemroz
 */
public class EdytujPietro extends javax.swing.JDialog {

    /** Creates new form EdytujPietro */
    public EdytujPietro(java.awt.Frame parent, boolean modal, String s, int idListy) {
        super(parent, modal);
        initComponents();
        this.s = s;
        tfNazwaPietra.setText(s.split("#")[0]);
        this.index = Integer.parseInt(s.split("#")[1]);
        this.idListy = idListy;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfNazwaPietra = new javax.swing.JTextField();
        btnEdytujPietro = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Edytuj piętro");

        jLabel1.setText("Nazwa:");
        jLabel1.setName("jLabel1"); // NOI18N

        tfNazwaPietra.setName("tfNazwaPietra"); // NOI18N

        btnEdytujPietro.setText("Edytuj");
        btnEdytujPietro.setName("btnEdytujPietro"); // NOI18N
        btnEdytujPietro.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnEdytujPietroMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEdytujPietro)
                    .addComponent(tfNazwaPietra, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfNazwaPietra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEdytujPietro)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-185)/2, (screenSize.height-106)/2, 185, 106);
    }// </editor-fold>//GEN-END:initComponents

    private void btnEdytujPietroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnEdytujPietroMouseClicked
        if (!tfNazwaPietra.getText().equals(s)) {
            new MsPietroDAO().ustawNazwe(index, tfNazwaPietra.getText());
            (View.ProjektorPanel.getLstPietra()).set(idListy, tfNazwaPietra.getText()+"#"+index);
            dispose();
        }
    }//GEN-LAST:event_btnEdytujPietroMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                EdytujPietro dialog = new EdytujPietro(new javax.swing.JFrame(), true, new String(), 0);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEdytujPietro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField tfNazwaPietra;
    // End of variables declaration//GEN-END:variables
    private String s;
    private int index;
    private int idListy;
}
